// k个一组翻转链表
/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @param {number} k
 * @return {ListNode}
 */
 var reverseKGroup = function(head, k) {
    let a = head,b = head ;
    for(let i = 0 ;i < k ;i++){
        if(b==null) return head;
        b=b.next;
    }
    const newH = reverse(a,b);
    a.next=reverseKGroup(b,k);
    return  newH;
    }
    function reverse(a,b) {
      let pre = null;
      let cur = a;
      let next = a;
      while(cur!=b){
          next=cur.next;
          cur.next=pre;
          pre=cur;
          cur=next;
          
      }
      return pre;
    }